using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public class SqlPos_SalesReturnDetailProvider:DataAccessObject
{
	public SqlPos_SalesReturnDetailProvider()
    {
    }


    public bool DeletePos_SalesReturnDetail(int pos_SalesReturnDetailID)
    {
        using (SqlConnection connection = new SqlConnection(this.ConnectionString))
        {
            SqlCommand cmd = new SqlCommand("GP_DeletePos_SalesReturnDetail", connection);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@Pos_SalesReturnDetailID", SqlDbType.Int).Value = pos_SalesReturnDetailID;
            connection.Open();

            int result = cmd.ExecuteNonQuery();
            return (result == 1);
        }
    }

    public List<Pos_SalesReturnDetail> GetAllPos_SalesReturnDetails()
    {
        using (SqlConnection connection = new SqlConnection(this.ConnectionString))
        {
            SqlCommand command = new SqlCommand("GP_GetAllPos_SalesReturnDetails", connection);
            command.CommandType = CommandType.StoredProcedure;
            connection.Open();
            IDataReader reader = command.ExecuteReader(CommandBehavior.Default);

            return GetPos_SalesReturnDetailsFromReader(reader);
        }
    }
    public List<Pos_SalesReturnDetail> GetPos_SalesReturnDetailsFromReader(IDataReader reader)
    {
        List<Pos_SalesReturnDetail> pos_SalesReturnDetails = new List<Pos_SalesReturnDetail>();

        while (reader.Read())
        {
            pos_SalesReturnDetails.Add(GetPos_SalesReturnDetailFromReader(reader));
        }
        return pos_SalesReturnDetails;
    }

    public Pos_SalesReturnDetail GetPos_SalesReturnDetailFromReader(IDataReader reader)
    {
        try
        {
            Pos_SalesReturnDetail pos_SalesReturnDetail = new Pos_SalesReturnDetail
                (
                    (int)reader["Pos_SalesReturnDetailID"],
                    (int)reader["LocalSalesDetailID"],
                    (int)reader["RemoteSalesDetailID"],
                    (int)reader["ProductID"],
                    (int)reader["Quantity"],
                    (int)reader["WorkStationID"],
                    (decimal)reader["CostPrice"],
                    (decimal)reader["SalesPrice"],
                    (decimal)reader["DiscountPercentage"],
                    (decimal)reader["DiscountAmount"],
                    (decimal)reader["VATPercentage"],
                    (decimal)reader["VATAmount"],
                    (int)reader["LocalPos_TransactionMasterID"],
                    (int)reader["SererPos_TransactionMasterID"],
                    (int)reader["LocalTransactionID"],
                    (int)reader["ServerTransactionID"],
                    (int)reader["LocalPos_SalesMasterID"],
                    (int)reader["ServerPos_SalesMasterID"],
                    (int)reader["LocalFinishedGoodAssetJournalDetailID"],
                    (int)reader["LocalCostOfGoodsSoldJournalDetailID"],
                    (int)reader["LocalSalesRevinueJournalDetailID"],
                    (int)reader["LocalVATIncludingJournalDetailID"],
                    (int)reader["LocalVATExcludingJournalDetailID"],
                    (int)reader["LocalDiscountJournalDetailID"],
                    (int)reader["ServerFinishedGoodAssetJournalDetailID"],
                    (int)reader["ServerCostOfGoodsSoldJournalDetailID"],
                    (int)reader["ServerSalesRevinueJournalDetailID"],
                    (int)reader["ServerVATIncludingJournalDetailID"],
                    (int)reader["ServerVATExcludingJournalDetailID"],
                    (int)reader["ServerDiscountJournalDetailID"],
                    (int)reader["StatusID"],
                    reader["ExtraField1"].ToString(),
                    reader["ExtraField2"].ToString(),
                    reader["ExtraField3"].ToString(),
                    reader["ExtraField4"].ToString(),
                    reader["ExtraField5"].ToString(),
                    reader["ExtraField6"].ToString(),
                    reader["ExtraField7"].ToString(),
                    reader["ExtraField8"].ToString(),
                    reader["ExtraField9"].ToString(),
                    reader["ExtraField10"].ToString()
                );
             return pos_SalesReturnDetail;
        }
        catch(Exception ex)
        {
            return null;
        }
    }

    public Pos_SalesReturnDetail GetPos_SalesReturnDetailByID(int pos_SalesReturnDetailID)
    {
        using (SqlConnection connection = new SqlConnection(this.ConnectionString))
        {
            SqlCommand command = new SqlCommand("GP_GetPos_SalesReturnDetailByID", connection);
            command.CommandType = CommandType.StoredProcedure;
            command.Parameters.Add("@Pos_SalesReturnDetailID", SqlDbType.Int).Value = pos_SalesReturnDetailID;
            connection.Open();
            IDataReader reader = command.ExecuteReader(CommandBehavior.SingleRow);

            if (reader.Read())
            {
                return GetPos_SalesReturnDetailFromReader(reader);
            }
            else
            {
                return null;
            }
        }
    }

    public int InsertPos_SalesReturnDetail(Pos_SalesReturnDetail pos_SalesReturnDetail)
    {
        using (SqlConnection connection = new SqlConnection(this.ConnectionString))
        {
            SqlCommand cmd = new SqlCommand("GP_InsertPos_SalesReturnDetail", connection);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@Pos_SalesReturnDetailID", SqlDbType.Int).Direction = ParameterDirection.Output;
            cmd.Parameters.Add("@LocalSalesDetailID", SqlDbType.Int).Value = pos_SalesReturnDetail.LocalSalesDetailID;
            cmd.Parameters.Add("@RemoteSalesDetailID", SqlDbType.Int).Value = pos_SalesReturnDetail.RemoteSalesDetailID;
            cmd.Parameters.Add("@ProductID", SqlDbType.Int).Value = pos_SalesReturnDetail.ProductID;
            cmd.Parameters.Add("@Quantity", SqlDbType.Int).Value = pos_SalesReturnDetail.Quantity;
            cmd.Parameters.Add("@WorkStationID", SqlDbType.Int).Value = pos_SalesReturnDetail.WorkStationID;
            cmd.Parameters.Add("@CostPrice", SqlDbType.Decimal).Value = pos_SalesReturnDetail.CostPrice;
            cmd.Parameters.Add("@SalesPrice", SqlDbType.Decimal).Value = pos_SalesReturnDetail.SalesPrice;
            cmd.Parameters.Add("@DiscountPercentage", SqlDbType.Decimal).Value = pos_SalesReturnDetail.DiscountPercentage;
            cmd.Parameters.Add("@DiscountAmount", SqlDbType.Decimal).Value = pos_SalesReturnDetail.DiscountAmount;
            cmd.Parameters.Add("@VATPercentage", SqlDbType.Decimal).Value = pos_SalesReturnDetail.VATPercentage;
            cmd.Parameters.Add("@VATAmount", SqlDbType.Decimal).Value = pos_SalesReturnDetail.VATAmount;
            cmd.Parameters.Add("@LocalPos_TransactionMasterID", SqlDbType.Int).Value = pos_SalesReturnDetail.LocalPos_TransactionMasterID;
            cmd.Parameters.Add("@SererPos_TransactionMasterID", SqlDbType.Int).Value = pos_SalesReturnDetail.SererPos_TransactionMasterID;
            cmd.Parameters.Add("@LocalTransactionID", SqlDbType.Int).Value = pos_SalesReturnDetail.LocalTransactionID;
            cmd.Parameters.Add("@ServerTransactionID", SqlDbType.Int).Value = pos_SalesReturnDetail.ServerTransactionID;
            cmd.Parameters.Add("@LocalPos_SalesMasterID", SqlDbType.Int).Value = pos_SalesReturnDetail.LocalPos_SalesMasterID;
            cmd.Parameters.Add("@ServerPos_SalesMasterID", SqlDbType.Int).Value = pos_SalesReturnDetail.ServerPos_SalesMasterID;
            cmd.Parameters.Add("@LocalFinishedGoodAssetJournalDetailID", SqlDbType.Int).Value = pos_SalesReturnDetail.LocalFinishedGoodAssetJournalDetailID;
            cmd.Parameters.Add("@LocalCostOfGoodsSoldJournalDetailID", SqlDbType.Int).Value = pos_SalesReturnDetail.LocalCostOfGoodsSoldJournalDetailID;
            cmd.Parameters.Add("@LocalSalesRevinueJournalDetailID", SqlDbType.Int).Value = pos_SalesReturnDetail.LocalSalesRevinueJournalDetailID;
            cmd.Parameters.Add("@LocalVATIncludingJournalDetailID", SqlDbType.Int).Value = pos_SalesReturnDetail.LocalVATIncludingJournalDetailID;
            cmd.Parameters.Add("@LocalVATExcludingJournalDetailID", SqlDbType.Int).Value = pos_SalesReturnDetail.LocalVATExcludingJournalDetailID;
            cmd.Parameters.Add("@LocalDiscountJournalDetailID", SqlDbType.Int).Value = pos_SalesReturnDetail.LocalDiscountJournalDetailID;
            cmd.Parameters.Add("@ServerFinishedGoodAssetJournalDetailID", SqlDbType.Int).Value = pos_SalesReturnDetail.ServerFinishedGoodAssetJournalDetailID;
            cmd.Parameters.Add("@ServerCostOfGoodsSoldJournalDetailID", SqlDbType.Int).Value = pos_SalesReturnDetail.ServerCostOfGoodsSoldJournalDetailID;
            cmd.Parameters.Add("@ServerSalesRevinueJournalDetailID", SqlDbType.Int).Value = pos_SalesReturnDetail.ServerSalesRevinueJournalDetailID;
            cmd.Parameters.Add("@ServerVATIncludingJournalDetailID", SqlDbType.Int).Value = pos_SalesReturnDetail.ServerVATIncludingJournalDetailID;
            cmd.Parameters.Add("@ServerVATExcludingJournalDetailID", SqlDbType.Int).Value = pos_SalesReturnDetail.ServerVATExcludingJournalDetailID;
            cmd.Parameters.Add("@ServerDiscountJournalDetailID", SqlDbType.Int).Value = pos_SalesReturnDetail.ServerDiscountJournalDetailID;
            cmd.Parameters.Add("@StatusID", SqlDbType.Int).Value = pos_SalesReturnDetail.StatusID;
            cmd.Parameters.Add("@ExtraField1", SqlDbType.NVarChar).Value = pos_SalesReturnDetail.ExtraField1;
            cmd.Parameters.Add("@ExtraField2", SqlDbType.NVarChar).Value = pos_SalesReturnDetail.ExtraField2;
            cmd.Parameters.Add("@ExtraField3", SqlDbType.NVarChar).Value = pos_SalesReturnDetail.ExtraField3;
            cmd.Parameters.Add("@ExtraField4", SqlDbType.NVarChar).Value = pos_SalesReturnDetail.ExtraField4;
            cmd.Parameters.Add("@ExtraField5", SqlDbType.NVarChar).Value = pos_SalesReturnDetail.ExtraField5;
            cmd.Parameters.Add("@ExtraField6", SqlDbType.NVarChar).Value = pos_SalesReturnDetail.ExtraField6;
            cmd.Parameters.Add("@ExtraField7", SqlDbType.NVarChar).Value = pos_SalesReturnDetail.ExtraField7;
            cmd.Parameters.Add("@ExtraField8", SqlDbType.NVarChar).Value = pos_SalesReturnDetail.ExtraField8;
            cmd.Parameters.Add("@ExtraField9", SqlDbType.NVarChar).Value = pos_SalesReturnDetail.ExtraField9;
            cmd.Parameters.Add("@ExtraField10", SqlDbType.NVarChar).Value = pos_SalesReturnDetail.ExtraField10;
            connection.Open();

            int result = cmd.ExecuteNonQuery();
            return (int)cmd.Parameters["@Pos_SalesReturnDetailID"].Value;
        }
    }

    public bool UpdatePos_SalesReturnDetail(Pos_SalesReturnDetail pos_SalesReturnDetail)
    {
        using (SqlConnection connection = new SqlConnection(this.ConnectionString))
        {
            SqlCommand cmd = new SqlCommand("GP_UpdatePos_SalesReturnDetail", connection);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@Pos_SalesReturnDetailID", SqlDbType.Int).Value = pos_SalesReturnDetail.Pos_SalesReturnDetailID;
            cmd.Parameters.Add("@LocalSalesDetailID", SqlDbType.Int).Value = pos_SalesReturnDetail.LocalSalesDetailID;
            cmd.Parameters.Add("@RemoteSalesDetailID", SqlDbType.Int).Value = pos_SalesReturnDetail.RemoteSalesDetailID;
            cmd.Parameters.Add("@ProductID", SqlDbType.Int).Value = pos_SalesReturnDetail.ProductID;
            cmd.Parameters.Add("@Quantity", SqlDbType.Int).Value = pos_SalesReturnDetail.Quantity;
            cmd.Parameters.Add("@WorkStationID", SqlDbType.Int).Value = pos_SalesReturnDetail.WorkStationID;
            cmd.Parameters.Add("@CostPrice", SqlDbType.Decimal).Value = pos_SalesReturnDetail.CostPrice;
            cmd.Parameters.Add("@SalesPrice", SqlDbType.Decimal).Value = pos_SalesReturnDetail.SalesPrice;
            cmd.Parameters.Add("@DiscountPercentage", SqlDbType.Decimal).Value = pos_SalesReturnDetail.DiscountPercentage;
            cmd.Parameters.Add("@DiscountAmount", SqlDbType.Decimal).Value = pos_SalesReturnDetail.DiscountAmount;
            cmd.Parameters.Add("@VATPercentage", SqlDbType.Decimal).Value = pos_SalesReturnDetail.VATPercentage;
            cmd.Parameters.Add("@VATAmount", SqlDbType.Decimal).Value = pos_SalesReturnDetail.VATAmount;
            cmd.Parameters.Add("@LocalPos_TransactionMasterID", SqlDbType.Int).Value = pos_SalesReturnDetail.LocalPos_TransactionMasterID;
            cmd.Parameters.Add("@SererPos_TransactionMasterID", SqlDbType.Int).Value = pos_SalesReturnDetail.SererPos_TransactionMasterID;
            cmd.Parameters.Add("@LocalTransactionID", SqlDbType.Int).Value = pos_SalesReturnDetail.LocalTransactionID;
            cmd.Parameters.Add("@ServerTransactionID", SqlDbType.Int).Value = pos_SalesReturnDetail.ServerTransactionID;
            cmd.Parameters.Add("@LocalPos_SalesMasterID", SqlDbType.Int).Value = pos_SalesReturnDetail.LocalPos_SalesMasterID;
            cmd.Parameters.Add("@ServerPos_SalesMasterID", SqlDbType.Int).Value = pos_SalesReturnDetail.ServerPos_SalesMasterID;
            cmd.Parameters.Add("@LocalFinishedGoodAssetJournalDetailID", SqlDbType.Int).Value = pos_SalesReturnDetail.LocalFinishedGoodAssetJournalDetailID;
            cmd.Parameters.Add("@LocalCostOfGoodsSoldJournalDetailID", SqlDbType.Int).Value = pos_SalesReturnDetail.LocalCostOfGoodsSoldJournalDetailID;
            cmd.Parameters.Add("@LocalSalesRevinueJournalDetailID", SqlDbType.Int).Value = pos_SalesReturnDetail.LocalSalesRevinueJournalDetailID;
            cmd.Parameters.Add("@LocalVATIncludingJournalDetailID", SqlDbType.Int).Value = pos_SalesReturnDetail.LocalVATIncludingJournalDetailID;
            cmd.Parameters.Add("@LocalVATExcludingJournalDetailID", SqlDbType.Int).Value = pos_SalesReturnDetail.LocalVATExcludingJournalDetailID;
            cmd.Parameters.Add("@LocalDiscountJournalDetailID", SqlDbType.Int).Value = pos_SalesReturnDetail.LocalDiscountJournalDetailID;
            cmd.Parameters.Add("@ServerFinishedGoodAssetJournalDetailID", SqlDbType.Int).Value = pos_SalesReturnDetail.ServerFinishedGoodAssetJournalDetailID;
            cmd.Parameters.Add("@ServerCostOfGoodsSoldJournalDetailID", SqlDbType.Int).Value = pos_SalesReturnDetail.ServerCostOfGoodsSoldJournalDetailID;
            cmd.Parameters.Add("@ServerSalesRevinueJournalDetailID", SqlDbType.Int).Value = pos_SalesReturnDetail.ServerSalesRevinueJournalDetailID;
            cmd.Parameters.Add("@ServerVATIncludingJournalDetailID", SqlDbType.Int).Value = pos_SalesReturnDetail.ServerVATIncludingJournalDetailID;
            cmd.Parameters.Add("@ServerVATExcludingJournalDetailID", SqlDbType.Int).Value = pos_SalesReturnDetail.ServerVATExcludingJournalDetailID;
            cmd.Parameters.Add("@ServerDiscountJournalDetailID", SqlDbType.Int).Value = pos_SalesReturnDetail.ServerDiscountJournalDetailID;
            cmd.Parameters.Add("@StatusID", SqlDbType.Int).Value = pos_SalesReturnDetail.StatusID;
            cmd.Parameters.Add("@ExtraField1", SqlDbType.NVarChar).Value = pos_SalesReturnDetail.ExtraField1;
            cmd.Parameters.Add("@ExtraField2", SqlDbType.NVarChar).Value = pos_SalesReturnDetail.ExtraField2;
            cmd.Parameters.Add("@ExtraField3", SqlDbType.NVarChar).Value = pos_SalesReturnDetail.ExtraField3;
            cmd.Parameters.Add("@ExtraField4", SqlDbType.NVarChar).Value = pos_SalesReturnDetail.ExtraField4;
            cmd.Parameters.Add("@ExtraField5", SqlDbType.NVarChar).Value = pos_SalesReturnDetail.ExtraField5;
            cmd.Parameters.Add("@ExtraField6", SqlDbType.NVarChar).Value = pos_SalesReturnDetail.ExtraField6;
            cmd.Parameters.Add("@ExtraField7", SqlDbType.NVarChar).Value = pos_SalesReturnDetail.ExtraField7;
            cmd.Parameters.Add("@ExtraField8", SqlDbType.NVarChar).Value = pos_SalesReturnDetail.ExtraField8;
            cmd.Parameters.Add("@ExtraField9", SqlDbType.NVarChar).Value = pos_SalesReturnDetail.ExtraField9;
            cmd.Parameters.Add("@ExtraField10", SqlDbType.NVarChar).Value = pos_SalesReturnDetail.ExtraField10;
            connection.Open();

            int result = cmd.ExecuteNonQuery();
            return result == 1;
        }
    }
}
